<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03_JS数据类型</title>
</head>
<body>
    <script>
        //JS数据类型=原始类型+引用类型
        //原始类型:number string boolean null undefined
        var a=10;
        var b=66.66;
        console.log(a,typeof a,b,typeof b);/*  整数小数都是number */
        var c="hello";
        var d='q';
        console.log(c,typeof c,d,typeof d);/*  单引双引都是string */
        var e=true;
        var f=false;
        console.log(e,typeof e,f,typeof f);/*  true false都是boolean */
        var g;
        console.log(g,typeof g);/* 声明但未赋值为undefined */


        //引用类型
        let obj ={};//{} 对象
        console.log(obj,typeof obj);
        obj.name="迪丽热巴";
        obj.age=18;
        console.log(obj,typeof obj);
        console.log(obj.name);
        console.log(obj.age);

        let obj2= {
            name : "迪丽热巴",
            age : 18
        }
        console.log(obj2,typeof obj2);
        console.log(obj2.name);
        console.log(obj2.age);
        console.log(obj2.like);//访问对象不存在的属性时，返回undefined

        //数组
        let arr=[1,2,3,4,5];
        console.log(arr,typeof arr);
        console.log(arr.length);
        console.log(arr[0]);
        console.log(arr[1]);
        console.log(arr[2]);
        console.log(arr[3]);
        console.log(arr[4]);
        console.log(arr[100]);//访问数组不存在时，返回undefined

        //Number()将参数转换成数值类型，如果无法转换，则返回NaN
        console.log(Number(true),typeof Number(true));
        console.log(Number('123'));
        console.log(Number('abc'));//输出NaN


        //Boolean()将参数转换成布尔类型，如果参数为0，NaN,null，undefined，'',则返回false，其他返回true
        console.log(Boolean(0),typeof Boolean(0));//false
        console.log(Boolean(NaN));//false
        console.log(Boolean(null));//false
        console.log(Boolean(''));//false
        console.log(Boolean(undefined));//false
        console.log(Boolean(' '));//true
        console.log(Boolean(123));//true




    </script>
</body>
</html>